package com.qf.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @author wangyu
 * @Classname: TestJDBC
 * @Description: TEST
 * @date 2022-04-03 23:04
 */
public class TestJDBC {
    public static void main(String[] args) throws Exception{
//        1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");

//        2 获取链接
         String url="jdbc:mysql://localhost:3306/dbtest1?useUnicode=true&characterEncoding=utf8";
         String root="root";
         String pwd="12345";

        Connection connection = DriverManager.getConnection(url,root,pwd);//修改后

        if(connection != null){
            System.out.println("链接成功");
        }else {
            System.out.println("失败");
        }

//        3执行sql语句
        Statement statement = connection.createStatement();
//        4
        String sql = "insert into  books(book_isbn,book_name,book_nuthor) values(111,'wangyu','wangyu01')";

        int result =  statement.executeUpdate(sql);

        if(result == 1){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }

//        6 释放资源 先开后关
        statement.close();
        connection.close();
    }
}
